package exswing;

import java.awt.Color;
import java.awt.Panel;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;

public class Janela extends JFrame {

    private Panel p = new Panel();// cria uma nova janela para criar varios botoes

    public Janela() {
        super(" Minha primeira Janela ");
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        setSize(300, 200);

        // p.setBackground(Color.YELLOW);BVermelho
        JButton bVermelho = new JButton("vermelho");
        p.add(bVermelho);
        bVermelho.addMouseListener(new ManipuladorEvento(Color.RED));

        JButton bVerde = new JButton("verde");
        p.add(bVerde);
        bVerde.addMouseListener(new ManipuladorEvento(Color.GREEN));

        JButton bAzul = new JButton("azul");
        p.add(bAzul);
        bAzul.addMouseListener(new ManipuladorEvento(Color.BLUE));
        // p.add(new JButton("Azul")).addMouseListener(new ManipuladorEvento());
        //p.add(new JButton("Verde")).addMouseListener(new ManipuladorEvento());
        p.add(new JLabel("Cor clicada"));

        // p.addMouseListener(new ManipuladorEvento());
        this.setContentPane(p);
        setVisible(true);
    }

    private static class ManipuladorEvento extends MouseAdapter {

        private ManipuladorEvento(Color p) {
            
            
        }

        
        
        @Override
        public void mouseClicked(MouseEvent e) {
            //throw new UnsupportedOperationException("Not supported yet.");
            //JOptionPane.showMessageDialog(null, "Mouse Clicado ");
            JButton botaoclicado = (JButton) e.getSource();
            if (botaoclicado.getText().equals("vermelho")) {
                p.Background(color.RED);
            } else if (botaoclicado.getText().equals("verde")) {
                p.Background(color.GREEN);
            } else if (botaoclicado.getText().equals("azul")) {
                p.Background(color.BLUE);
            }
        }

        @Override
        public void mousePressed(MouseEvent e) {
            // throw new UnsupportedOperationException("Not supported yet.");
            // JOptionPane.showMessageDialog(null, "Mouse Liberado ");
        }

        @Override
        public void mouseReleased(MouseEvent e) {
            // throw new UnsupportedOperationException("Not supported yet.");
            JOptionPane.showMessageDialog(null, "");
        }

        @Override
        public void mouseEntered(MouseEvent e) {
            //throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public void mouseExited(MouseEvent e) {
            // throw new UnsupportedOperationException("Not supported yet.");
        }
    }

    public static void main(String[] args) {

        Janela j = new Janela();

    }
}
